import { request, BaseResponse } from '@/utils/request';
/**
 * @description 公共接口
 * @param {Namespace} isMock
 * @param isGetDataDirectly
 * @returns successMsg errorMsg
 */
/**
 * 获取系统登录信息
 */

export function GetUser() {
  return request<BaseResponse<Namespace.DataUser>>(
    {
      url: `/sys/user/getactiveuser`,
      method: 'get',
    },
    {
      isMock: false,
      isGetDataDirectly: false,
    },
  );
}
/**
 * 获取枚举数据
 */

export function GetMenu(query: string, especially?: { id?: string; rfq_id?: string }) {
  return request<BaseResponse<Array<Namespace.menuType>>>(
    {
      url: `/sys/unit/getenumlist/${query}`,
      method: 'get',
      params: especially,
    },
    {
      isMock: false,
      isGetDataDirectly: false,
    },
  );
}

/**
 * 下载文件
 */

export function downloadFile(id: number) {
  return request<BaseResponse>(
    {
      responseType: 'blob',
      url: `/sys/file/getfile/${id}`,
      method: 'get',
    },
    {
      isMock: false,
      isGetDataDirectly: false,
    },
  );
}

/**
 * 文件上传
 */

export function fileUpload(state: number, folder: string) {
  return request<BaseResponse>(
    {
      url: `/sys/file/upload/${folder}?uploadtype=${state}`,
      method: 'post',
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    },
    {
      isMock: false,
      isGetDataDirectly: false,
      successMsg: '上传成功',
    },
  );
}

/**
 * 文件删除
 */

export function fileDelete(id: number) {
  return request<BaseResponse>(
    {
      url: `/sys/file/remove/${id}`,
      method: 'post',
    },
    {
      isMock: false,
      isGetDataDirectly: false,
      successMsg: '删除成功',
    },
  );
}
